package com.xbongbong.crm.util;

import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;

import java.util.Objects;

/**
 * @author 吴峰
 * @date 2021/12/24 11:20
 */
public class CrmPermissionUtil {


    public static boolean checkData(PaasFormDataEntityExt paasFormDataEntityExt, Integer subBusinessType) throws XbbException {
        if (Objects.isNull(paasFormDataEntityExt) || Objects.isNull(paasFormDataEntityExt.getId())){
            return true;
        }
        boolean recycle = (Objects.equals(subBusinessType, XbbRefTypeEnum.CUSTOMER_RECYCLE.getCode()) || Objects.equals(subBusinessType,XbbRefTypeEnum.CLUE_RECYCLE.getCode()) && Objects.equals(paasFormDataEntityExt.getDel(), DelEnum.DELETE.getDel()));
        if (recycle){
            // 客户回收站和线索回收站的单据del都是1
            return false;
        }
        if (Objects.equals(paasFormDataEntityExt.getDel(),DelEnum.DELETE.getDel()) || Objects.equals(paasFormDataEntityExt.getDel(), DelEnum.REMOVE_COMPLETELY.getDel())){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100404);
        }
        return false;
    }
}
